<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	
	function index(){
		
		if($this->input->post('act') == 'login'){
			$ret['url_title'] = '返回登录页';
			$ret['url_next']="javascript:history.go(-1)";
			
			$phone = $this->input->post('username');
			$password = $this->input->post('password');
			if($phone==''){
				$ret['msg'] = '请输入手机号';
			}elseif ($password==''){
				$ret['msg'] = '请输入密码';
			}else{
				$this->load->model('User_model', 'user');
				$tmpRow = $this->user->check_login_errnum($phone);
				if($tmpRow && $tmpRow['error_num']>=5){
					$ret['msg'] = '密码输入错误过多，该账户已被锁定，请联系客服解锁或者明日再试';
				}else{
					$user = $this->user->check_login($phone,$password);
					if(isset($user['user_id'])){
						if($user['fstatus']==3){
							$ret['msg'] = '该账户已注销';
						}elseif ($user['fstatus']==4){
							$ret['msg'] = '该账户已冻结';
						}else{
							$ip = $this->input->ip_address();
							$now = time();
							$user['login_time'] = $now;
							$this->session->set_userdata('ych_user',$user);
							
							$user = $this->user->get_by_uid($user['user_id']);
							$setArr = array(
								'logintime' => $user['logintime']+1,
								'uptime' => $user['lasttime'],
								'upip' => $user['lastip'],
								'lasttime' => $now,
								'error_num' => 0,
								'lastip' => $ip,
							);
							$this->user->update($setArr,array('user_id'=>$user['user_id']));
							
							/** 回款续投奖励发放 */
							
							$ret['msg'] = '登录成功';
							$ret['url_title'] = '前往用户中心';
							$ret['url_next']="/mobile/ucenter.html";
						}
					}else{
						$ret['msg'] = '账户或密码错误，请重试';
					}
				}
			}
			$this->load->view('mobile/msg',$ret);
		}else{
			$this->load->view('mobile/login');
		}
		
//		$ret['msg'] = "密码输入错误过多，该账户已被锁定，请联系客服解锁或者明日再试";
//		$this->load->view('mobile/msg',$ret);
	}
}